package yunjiao.designpatterns.observer;

/**
 * 短信订阅者
 *
 * @author yangyunjiao
 */
public class SMSSubscriber implements Observer {
    private final String name;
    private final String phone;

    public SMSSubscriber(String name, String phone) {
        this.name = name;
        this.phone = phone;
    }

    @Override
    public void update(Subject subject) {
        NewsPublisher publisher = (NewsPublisher) subject;
        System.out.println("发送短信到 " + phone + ": " + name +
                ", 最新消息: " + publisher.getLatestNews());
    }

    @Override
    public String getName() {
        return name + "(短信订阅者)";
    }
}
